export function renderPage(pages) {
    var listBox = document.querySelector('#list-box')
    if (pages.length == 0) {
        listBox.innerHTML = `
        <div class="alert alert-info" role="alert">
        sorry,empty
        </div>`;
    } else {
        let ul = '<ul class="list-group" id="list">';
        for (let item of pages) {
            ul += `<li class="list-group-item"><a href="${item.href}?id=${item.id}">${item.title}</></li>`
        }
        ul += '</ul>'
        listBox.innerHTML = ul;
    }
}
export function renderTags(tags) {
    let div = '<div class="flex mb-3">标签：';
    for (let item of tags) {
        div += `<button type="button" data-tag="${item}" class="mr-2 btn btn-sm btn-outline-primary">${item}</button>`
    }
    div += '</div>'
    document.querySelector('#tags-box').innerHTML = div;
}
export function readTextFile(fileName) {
    return new Promise((resolve, reject) => {
      try {
        var rawFile = new XMLHttpRequest()
        var filePath = '../markdown/' + fileName
        rawFile.open('GET', filePath, false)
        rawFile.onreadystatechange = function () {
          if (rawFile.readyState === 4) {
            if (rawFile.status === 200 || rawFile.status == 0) {
              var allText = rawFile.responseText
              resolve(allText)
            }
          }
        }
        rawFile.send(null)
      } catch (error) {
        reject(error)
      }
    })

  }

  export function initHighlight(){
    hljs.highlightAll()
  }